package com.nononsenseapps.feeder.net

import net.dankito.readability4j.Article
import net.dankito.readability4j.Readability4J
import okhttp3.OkHttpClient
import java.net.URL


object HtmlPageLoader {
    suspend fun loadHtmlPage(url:String, client: OkHttpClient = NetManager.defaultClient):String?{
        NetManager(client).curl(URL(url))?.let{
            return getReadabilityFullPage(url,it)
        }
        return null
    }

    fun getReadabilityFullPage(url:String,htmlString:String):String?{
        val readability4J = Readability4J(url, htmlString) // url is just needed to resolve relative urls
        val article: Article = readability4J.parse()
        return article.contentWithDocumentsCharsetOrUtf8;
    }
}